package com.pap.customerfeignapi;

import com.pap.customerfeignapi.dto.CustomerAddressDTO;
import com.pap.obj.vo.response.ResponseVO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class CustomerAddressServiceFeignFactory implements FallbackFactory<ICustomerAddressService> {

    private static Logger logger  =  LoggerFactory.getLogger(CustomerAddressServiceFeignFactory.class);

    @Override
    public ICustomerAddressService create(Throwable throwable) {
        //打印下异常 https://github.com/spring-cloud/spring-cloud-netflix/issues/1471
        return new CustomerAddressServiceAPIFallback() {
            @Override
            public ResponseVO<CustomerAddressDTO> selectOne(String id) {
                logger.error("CustomerAddressServiceFeignFactory selectOne error : [{}]", throwable.getMessage());
                return ResponseVO.validfail("服务端熔断异常!");
            }
        };
    }
}